<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 网站用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome  =1">
<!--    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">-->
    <style>
        html{
            overflow-y: scroll;
            overflow-x: scroll;
        }
        body{
            zoom: 100%;
        }
    </style>
    <link rel="stylesheet" href="/static/admin/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/global.css">

</head>
<body>

<div class="layui-fluid ">
    <div class="layui-card">
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                {if check_access('add')}
                <span class="layui-btn iframe" data-href="{:url('add')}" data-title="添加菜单" data-height="80%" data-width="80%">添加</span>
                {/if}
            </div>
            <form action="" class="layui-form" method="post"  onsubmit="return save_form(this)">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th style="width:8%">排序</th>
                        <th>id</th>
                        <th>菜单名称</th>
                        <th>菜单url</th>
                        <th>是否显示</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach $data as $k=>$v}
                    <tr {$v.pid!='顶级'?'hidden  ' : '  '}  {if $v.pid!="顶级"}data-pid="{$v->getData('pid')}"{/if}  {if $v.forefathers} &nbsp; forefathers="{$v.forefathers}"{/if}>
                        <td ><input style="padding-left: {$v.level * 10}px" class="layui-input" onkeyup="RegularNum0(this)" type='text' value="{$v.sort}" name="sort[]" autocomplete="off" ><input type='hidden' value="{$v.id}" name="id[]"></td>
                        <td>{$v.id}</td>
                        <td style="text-align: left;" >
                            <span class="layui-badge layui-bg-gray" style="margin-right: 10px;"> lv.{$v.level}</span>
                            {for start="1" end="$v[level]"}
                            <span style="width: 40px;display: inline-block"></span>
                            {/for}
                            {if $v.sons}
                            <span onclick="expand(this, {$v[id]})" style="width: 20px;display: inline-block">
                                <i class="layui-icon layui-icon-add-circle" style="font-size: 16px; color: #1E9FFF;"></i>
                            </span>
                            {else/}
                            <span style="width: 20px;display: inline-block"> </span>
                            {/if}

                            {if $v.level == 1}
                             <i class="layui-icon {$v.icon}"></i>
                            {/if}
                            {$v.name}
                        </td>
                        <td>{$v->getData('href')}</td>
                        <td>
                            <input type="checkbox" lay-text="菜单显示|菜单隐藏"  lay-skin="switch" value="1"  {$v.is_show?'checked':''} name="is_show" data-id="{$v.id}" >
                        </td>
                        <td>
                            {if check_access('add')}
                            <span class="layui-btn layui-btn-sm iframe" data-href="{:url('add', ['pid'=>$v->getData(pid)])}" data-title="增加菜单" data-width="80%" data-height="80%">增加同级</span>
                            <span class="layui-btn layui-btn-sm iframe" data-href="{:url('add', ['pid'=>$v.id])}" data-title="增加菜单" data-width="80%" data-height="80%">增加子级</span>
                            {/if}
                            {if check_access('editor')}
                            <span class="layui-btn layui-btn-sm layui-btn-normal iframe" data-href="{:url('editor', ['id'=>$v.id])}" data-title="编辑菜单" data-width="80%" data-height="80%">编辑</span>
                            {/if}
                            {if check_access('delete')}
                            <span class="layui-btn layui-btn-sm layui-btn-danger ajax_del" data-href="{:url('delete', ['id'=>$v.id])}" data-msg="确定删除菜单及其子菜单？">删除</span>
                            {/if}
                        </td>
                    </tr>
                    {/foreach}
                    </tbody>


                </table>
                <button class="layui-btn" onclick="$('.layui-form').attr('action','{:url("updateSort")}');$('.layui-form').submit();" type="button">排序</button>

            </form>
        </div>
    </div>
</div>

<script src="/static/admin//layuiadmin/layui/layui.js"></script>
<script src="/static/js/jquery-3.6.2.min.js"></script>
<script src="/static/js/crypto-js.min.js"></script>
<script src="/static/admin/js/global.js"></script>
<script>
    function expand(obj,id){
        let icon = $(obj).find('i');
        if(icon.hasClass('layui-icon-add-circle')){
            icon.removeClass('layui-icon-add-circle');
            icon.addClass('layui-icon-reduce-circle');
            $('tr[data-pid=' + id + ']').show();
        }else{
            icon.removeClass('layui-icon-reduce-circle');
            icon.addClass('layui-icon-add-circle');
            let  forefathers = $('tr[forefathers*=",' + id + ',"]');
            forefathers.find("i.layui-icon-reduce-circle").removeClass('layui-icon-reduce-circle').addClass('layui-icon-add-circle');
            forefathers.hide();
        }

    }
    let form = layui.form;
    form.on('switch', function (data){
        let name = data.elem.name;
        let checked = data.elem.checked;
        let is_show = checked ? 1 : 0;
        if(name === 'is_show'){
            let id = $(data.elem).data('id');
            $.post("{:url('setShow')}",{id, is_show},(res)=>{
                layer.msg(res.msg)
            })
        }
    })
</script>
</body>
</html>
